package ru.spbau.lifeincube.gui3d.interpolator;

import javafx.animation.Interpolator;

public class SpringInterpolator extends Interpolator{

	private double amplitude = 1.0;
	private double mass = 0.058;
	private double stiffness = 12.0;
	private double phase = 0.0;

	private boolean bounce = false;
	private double pulsation;

	public SpringInterpolator() {
		pulsation = Math.sqrt(stiffness / mass);
	}

	@Override
	protected double curve(double t) {
		double t2 = -Math.cos(pulsation*t+phase+Math.PI) * (1-t) * amplitude ;
		if(bounce) {
			return 1-Math.abs(t2);
		} else {
			return 1-t2;
		}
	}

	public double getAmplitude() {
		return amplitude;
	}

	public void setAmplitude(double amplitude) {
		this.amplitude = amplitude;
	}

	public double getMass() {
		return mass;
	}

	public void setMass(double mass) {
		this.mass = mass;
	}

	public double getStiffness() {
		return stiffness;
	}

	public void setStiffness(double stiffness) {
		this.stiffness = stiffness;
	}

	public double getPhase() {
		return phase;
	}

	public void setPhase(double phase) {
		this.phase = phase;
	}

	public boolean isBounce() {
		return bounce;
	}

	public void setBounce(boolean bounce) {
		this.bounce = bounce;
	}
}
